home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / JAVA / AWT / IMAGE / MemoryImageSource.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-14  |  2.5 KB  |  124 lines

  1. package java.awt.image;
  2.  
  3. import java.util.Hashtable;
  4.  
  5. public class MemoryImageSource implements ImageProducer {
  6.    int width;
  7.    int height;
  8.    ColorModel model;
  9.    Object pixels;
  10.    int pixeloffset;
  11.    int pixelscan;
  12.    Hashtable properties;
  13.    private ImageConsumer theConsumer;
  14.  
  15.    public MemoryImageSource(int var1, int var2, ColorModel var3, byte[] var4, int var5, int var6) {
  16.       this.initialize(var1, var2, var3, var4, var5, var6, (Hashtable)null);
  17.    }
  18.  
  19.    public MemoryImageSource(int var1, int var2, ColorModel var3, byte[] var4, int var5, int var6, Hashtable var7) {
  20.       this.initialize(var1, var2, var3, var4, var5, var6, var7);
  21.    }
  22.  
  23.    public MemoryImageSource(int var1, int var2, ColorModel var3, int[] var4, int var5, int var6) {
  24.       this.initialize(var1, var2, var3, var4, var5, var6, (Hashtable)null);
  25.    }
  26.  
  27.    public MemoryImageSource(int var1, int var2, ColorModel var3, int[] var4, int var5, int var6, Hashtable var7) {
  28.       this.initialize(var1, var2, var3, var4, var5, var6, var7);
  29.    }
  30.  
  31.    private void initialize(int var1, int var2, ColorModel var3, Object var4, int var5, int var6, Hashtable var7) {
  32.       this.width = var1;
  33.       this.height = var2;
  34.       this.model = var3;
  35.       this.pixels = var4;
  36.       this.pixeloffset = var5;
  37.       this.pixelscan = var6;
  38.       if (var7 == null) {
  39.          var7 = new Hashtable();
  40.       }
  41.  
  42.       this.properties = var7;
  43.    }
  44.  
  45.    public MemoryImageSource(int var1, int var2, int[] var3, int var4, int var5) {
  46.       if (ColorModel.RGBdefault == null) {
  47.          ColorModel.RGBdefault = new DirectColorModel(32, 16711680, 65280, 255, -16777216);
  48.       }
  49.  
  50.       this.initialize(var1, var2, ColorModel.RGBdefault, var3, var4, var5, (Hashtable)null);
  51.    }
  52.  
  53.    public MemoryImageSource(int var1, int var2, int[] var3, int var4, int var5, Hashtable var6) {
  54.       if (ColorModel.RGBdefault == null) {
  55.          ColorModel.RGBdefault = new DirectColorModel(32, 16711680, 65280, 255, -16777216);
  56.       }
  57.  
  58.       this.initialize(var1, var2, ColorModel.RGBdefault, var3, var4, var5, var6);
  59.    }
  60.  
  61.    public synchronized void addConsumer(ImageConsumer var1) {
  62.       this.theConsumer = var1;
  63.  
  64.       try {
  65.          this.produce();
  66.       } catch (Exception var2) {
  67.          if (this.theConsumer != null) {
  68.             this.theConsumer.imageComplete(1);
  69.          }
  70.       }
  71.  
  72.       this.theConsumer = null;
  73.    }
  74.  
  75.    public synchronized boolean isConsumer(ImageConsumer var1) {
  76.       return var1 == this.theConsumer;
  77.    }
  78.  
  79.    public synchronized void removeConsumer(ImageConsumer var1) {
  80.       if (this.theConsumer == var1) {
  81.          this.theConsumer = null;
  82.       }
  83.  
  84.    }
  85.  
  86.    public void startProduction(ImageConsumer var1) {
  87.       this.addConsumer(var1);
  88.    }
  89.  
  90.    public void requestTopDownLeftRightResend(ImageConsumer var1) {
  91.    }
  92.  
  93.    private void produce() {
  94.       if (this.theConsumer != null) {
  95.          this.theConsumer.setDimensions(this.width, this.height);
  96.       }
  97.  
  98.       if (this.theConsumer != null) {
  99.          this.theConsumer.setProperties(this.properties);
  100.       }
  101.  
  102.       if (this.theConsumer != null) {
  103.          this.theConsumer.setColorModel(this.model);
  104.       }
  105.  
  106.       if (this.theConsumer != null) {
  107.          this.theConsumer.setHints(30);
  108.       }
  109.  
  110.       if (this.theConsumer != null) {
  111.          if (this.pixels instanceof byte[]) {
  112.             this.theConsumer.setPixels(0, 0, this.width, this.height, this.model, (byte[])this.pixels, this.pixeloffset, this.pixelscan);
  113.          } else {
  114.             this.theConsumer.setPixels(0, 0, this.width, this.height, this.model, (int[])this.pixels, this.pixeloffset, this.pixelscan);
  115.          }
  116.       }
  117.  
  118.       if (this.theConsumer != null) {
  119.          this.theConsumer.imageComplete(3);
  120.       }
  121.  
  122.    }
  123. }
  124.